package com.db4o.odbgen.plugins.java.maingenerator.typedxmlschema;

import java.util.List;

import com.db4o.odbgen.OdbgenException;

/**
 * 
 * Represents a method declaration within a class.
 * No content is kept here.
 * @author liviug
 */
public class TSMethodDeclaration {
    
    private boolean _isConstructor;
    private List<TSModifier> _modifiers;
    private DataType _type;
    private String _name;
    private List<TSMethodParameter> _parameters;

    /**
     * Constructs a method declaration given it's fields.
     * @throws OdbgenException 
     */
    public TSMethodDeclaration(
            boolean isConstructor,
            List<TSModifier> modifiers,
            DataType type,
            String name,
            List<TSMethodParameter> parameters
        ) throws OdbgenException{
        this._isConstructor = isConstructor;
        this._modifiers = modifiers;
        this._type = type;
        this._name = name;
        this._parameters = parameters;
        
        if(this._isConstructor==true && this._type!=null){
            throw new OdbgenException("A type was provide for constructor '%s'.", name);
        }
        else if(this._isConstructor==false && this._type==null){
            throw new OdbgenException("A type must be provided for method '%s'.", name);
        }
        
    }

    /**
     * Tells whether this method represents a constructor or not..
     * If this is true, this.getType() will return null. 
     */
    public boolean isConstructor(){
        return this._isConstructor;
    }
    
    
    /**
     * Returns the modifiers of this field.
     */
    public List<TSModifier> getModifiers(){
        return this._modifiers;
    }

    /**
     * Returns the type of this field.
     */
    public DataType getType(){
        return this._type;
    }
    
    /**
     * Returns the name of this field.
     */
    public String getName(){
        return this._name;
    }

    /**
     * Returns the list of parameters of this method.
     */
    public List<TSMethodParameter> getParameters(){
        return this._parameters;
    }
    
}
